﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using System.Text.Json;
using SmartAPI.SmartArchive;
using SmartAPI.SmartArchive.Dto;
using OcrAndFileApi;

namespace SmartAPI
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var services = new ServiceCollection();
            var jsonOptions = new JsonSerializerOptions
            {
                Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            };
            services.AddHttpApi<IOcrApi>()
                .ConfigureHttpApi(o =>
                {
                    o.HttpHost = new Uri("http://211.155.90.103:8506");
                    o.JsonSerializeOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
                    o.JsonSerializeOptions.IgnoreNullValues=true;
                    o.JsonDeserializeOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
                });

           


            services.AddLogging(o=>
            {
                o.AddConsole();
            });
            var serviceProvider = services.BuildServiceProvider();

            var ocrApi = serviceProvider.GetService<IOcrApi>();
            var generalResult = await ocrApi.GeneralAsync(new GeneralRequestDto
            {
                Image = ImageExtension.GetImage("sample.jpg"),
                Scene = "print",
            });
            Console.WriteLine("通用文字识别结果");
            Console.WriteLine(JsonSerializer.Serialize(generalResult, jsonOptions));
            Console.ReadKey();
        }

        
    }
}
